home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / csdudes.exe / CSDUDES.CPP < prev    next >
Text File  |  1992-06-25  |  7KB  |  217 lines

  1. // Personnell DataBase
  2. // (C) Copyright 1992 Campbell Soup Company by Andrew Frantz
  3. // CSDUDES.CPP
  4. // contains the source for the TApplication class and the main driver
  5. //    CIS --- 70712,3547
  6. // =====================================================================
  7. #include "csdudes.hpp"
  8. // =====================================================================
  9. // The first PX data class must also init the engine
  10. // initialization of static member vars
  11. PXPerson* TPersonnellApp::PersonDB = new PXPerson();
  12. PXCostCtr* TPersonnellApp::CostCtrDB = new PXCostCtr();
  13. // =====================================================================
  14. void testCore()
  15. {
  16.     char mess[80];
  17.     sprintf(mess, "Coreleft = %lu", (unsigned long)    coreleft());
  18.     messageBox(mess, mfError);
  19. }
  20. // ============ TV Application class ===================================
  21. TPersonnellApp::TPersonnellApp() :
  22.     TProgInit( &TPersonnellApp::initStatusLine,
  23.         &TPersonnellApp::initMenuBar,
  24.         &TPersonnellApp::initDeskTop)
  25. {
  26. }
  27. // =====================================================================
  28. void TPersonnellApp::handleEvent(TEvent& event)
  29. {
  30.     TApplication::handleEvent(event);
  31.     TDialog *dialog;
  32.  
  33.     if( event.what == evCommand )
  34.     {
  35.         switch( event.message.command )
  36.         {
  37.             case cmPersonAddDialog:
  38.                 // testCore();
  39.                 dialog = (TPersonDlg *) validView( new TPersonDlg("Add Person", TPersonDlg::AddDlg));
  40.                 if(dialog != 0)
  41.                     deskTop->execView(dialog);
  42.                 destroy(dialog);
  43.                 // testCore();
  44.                 break;
  45.             case cmPersonEditDialog:
  46.                 // testCore();
  47.                 dialog = (TPersonDlg *) validView( new TPersonDlg("Edit Person", TPersonDlg::EditDlg));
  48.                 if(dialog != 0)
  49.                     deskTop->execView(dialog);
  50.                 destroy(dialog);
  51.                 // testCore();
  52.                 break;
  53.             case cmCostCtrAddDialog:
  54.                 dialog = (TCostCtrDlg *) validView( new TCostCtrDlg("Add Cost Center", TCostCtrDlg::AddDlg));
  55.                 if(dialog != 0)
  56.                     deskTop->execView(dialog);
  57.                 destroy(dialog);
  58.                 break;
  59.             case cmCostCtrEditDialog:
  60.                 dialog = (TCostCtrDlg *) validView( new TCostCtrDlg("Edit Cost Center", TCostCtrDlg::EditDlg));
  61.                 if(dialog != 0)
  62.                     deskTop->execView(dialog);
  63.                 destroy(dialog);
  64.                 break;
  65.             case cmAboutCmd:            //  About Dialog Box
  66.                 aboutDlgBox();
  67.                 break;
  68.             default:
  69.                 return;
  70.         }
  71.         clearEvent( event );            // clear event after handling
  72.     }
  73. }
  74. // =====================================================================
  75. TMenuBar *TPersonnellApp::initMenuBar( TRect r )
  76. {
  77.     TSubMenu& sub1 =
  78.         *new TSubMenu( "~\360~", 0 ) +
  79.         *new TMenuItem( "~A~bout...", cmAboutCmd, kbNoKey, hcNoContext);
  80.  
  81.     TSubMenu& sub2 =
  82.         *new TSubMenu( "~D~ata Entry", kbAltD )+
  83.         *new TMenuItem( "~P~eople", cmPersonAddDialog, kbF3, hcNoContext, "F3" )+
  84.         *new TMenuItem( "~C~ost Ctr", cmCostCtrAddDialog, kbF4, hcNoContext, "F4" )+
  85.         newLine()+
  86.         *new TMenuItem( "E~x~it", cmQuit, cmQuit, hcNoContext, "Alt-X" );
  87.  
  88.     TSubMenu& sub3 =
  89.         *new TSubMenu( "Data ~E~dit", kbAltE )+
  90.         *new TMenuItem( "~P~eople", cmPersonEditDialog, kbF5, hcNoContext, "F5" )+
  91.         *new TMenuItem( "~C~ost Ctr", cmCostCtrEditDialog, kbF6, hcNoContext, "F6" );
  92.  
  93.     r.b.y =  r.a.y + 1;
  94.     return (new TMenuBar( r, sub1 + sub2 + sub3 ) );
  95. }
  96. // =====================================================================
  97. TStatusLine *TPersonnellApp::initStatusLine( TRect r )
  98. {
  99.     r.a.y = r.b.y - 1;     // move top to 1 line above bottom
  100.     return (new TStatusLine( r,
  101.         *new TStatusDef( 0, 0xFFFF ) +
  102.         *new TStatusItem( "~Alt-X~ Exit", kbAltX, cmQuit ) +
  103.         *new TStatusItem( 0, kbF10, cmMenu ) ));
  104. }
  105. // =====================================================================
  106. void TPersonnellApp::aboutDlgBox()
  107. {
  108.      TDialog *aboutBox = new TDialog(TRect(0, 0, 39, 13), "About");
  109.  
  110.      aboutBox->insert(
  111.         new TStaticText(TRect(9, 2, 30, 9),
  112.           "\003Personnell DataBase\n\003\n"     // These strings will be
  113.           "\003Beta Version\n\003\n"           // concatenated by the compiler.
  114.           "\003Copyright (c) 1992\n\003\n"    // The Ctrl-C centers the line.
  115.           "\003Campbell Soup"
  116.           )
  117.         );
  118.  
  119.     aboutBox->insert(new TButton(TRect(14, 10, 25, 12), " OK", cmOK, bfDefault));
  120.  
  121.     aboutBox->options |= ofCentered;
  122.  
  123.     deskTop->execView(aboutBox);
  124.  
  125.     destroy( aboutBox );
  126. }
  127. // =====================================================================
  128. // AFF add functionality for Enter key on field and Select Button
  129. // Stuff a message into event queue if double click or Button hit
  130. void TMyListBox::handleEvent(TEvent& event)
  131. {
  132.     int doIt=0;
  133.     if((event.what == evMouseDown) && (event.mouse.doubleClick))
  134.     {
  135.         doIt = 1;
  136.     }
  137.     else if((event.what == evKeyDown) && (event.keyDown.keyCode == kbEnter))
  138.     {
  139.         doIt = 1;
  140.     }     
  141.     else
  142.         doIt=0;
  143.  
  144.     if(doIt)
  145.     {
  146.         message(owner,evBroadcast,cmListItemSelected,this);
  147.         clearEvent(event);
  148.     }
  149.     TListBox::handleEvent(event);
  150. }
  151. // =====================================================================
  152. TCCListDlg::TCCListDlg(TRect& bounds,char *aTitle) :
  153.         TDialog(bounds,aTitle),
  154.         TWindowInit(&TCCListDlg::initFrame)
  155. {
  156.     TStringCollection *theCollection = new TStringCollection(100,10);
  157.  
  158.     TPersonnellApp::CostCtrDB->recfirst();
  159.     do {
  160.         TPersonnellApp::CostCtrDB->recget();
  161.         TPersonnellApp::CostCtrDB->CostCtr.get();
  162.         theCollection->insert(newStr(TPersonnellApp::CostCtrDB->CostCtr));
  163.     } while(TPersonnellApp::CostCtrDB->recnext() == PXSUCCESS);
  164.  
  165.     options |= ofCentered;
  166.     eventMask |= evBroadcast;
  167.  
  168.     TScrollBar *listScroller = new TScrollBar(TRect(47,2,48,10));
  169.  
  170.     listBox = new TMyListBox(TRect(3,2,47,10),2,listScroller);
  171.  
  172.     listBox->newList(theCollection);
  173.  
  174.     insert(listBox);
  175.     insert(listScroller);
  176.  
  177. //    insert(new TButton(TRect(22,19,32,21),"~S~elect",cmListItemSelected,bfDefault));
  178.  
  179.     selectNext(False);
  180. }
  181. // =====================================================================
  182. void TCCListDlg::handleEvent(TEvent& event)
  183. {
  184.     char msg[20];
  185.     if ((event.what == evBroadcast) && (event.message.command == cmListItemSelected))
  186.     {
  187.         listBox->getText(msg,listBox->focused,5);
  188.         message(owner,evBroadcast,cmInterView,msg);  //Inter-view communication
  189.         clearEvent(event);
  190.         message(owner,evCommand,cmClose,this);  // close the ListDlg
  191.         clearEvent(event);
  192.     }
  193.     TDialog::handleEvent(event);
  194. }
  195. // =====================================================================
  196. // Addeds this from C++ Report February 1992
  197. // called when new object fails.. set with set_new_handler(new_failure)
  198. void new_failure()
  199. {
  200.     messageBox("Memory Allocation error ...Exiting !", mfError);
  201.     cout     << "Memory Allocation error ...Exiting !\n";
  202.     PXExit();
  203.     exit(-1);
  204. }
  205. // =====================================================================
  206. int main(int argc, char **argv)
  207. {
  208.     set_new_handler(new_failure);
  209.     TPersonnellApp TestApp;
  210. //    testCore();
  211.     TestApp.run();
  212.     PXExit();
  213.     return 0;
  214. }
  215. // =====================================================================
  216.  
  217.